package pl.edu.mimuw.irs.core.model.design;

import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;

import pl.edu.mimuw.irs.core.model.analysis.subnet.AtomicSubnet;
import pl.edu.mimuw.irs.core.model.design.processing.Resource;
import pl.edu.mimuw.irs.core.model.design.processing.Role;
import pl.edu.mimuw.irs.core.model.design.processing.RoleInstance;
import pl.edu.mimuw.irs.core.util.Position;

/**
 * @author Jakub Rauch
 * Created on: 2009-05-07
 */
public class IRSResourceSet extends IRSPlace {
	
	// *** Attributes
	private List<Resource> resources;
	public List<Resource> getResources() {
		if (resources == null) resources = new LinkedList<Resource>();
		return resources;
	}
	public void setResources(List<Resource> resources) {
		this.resources = resources;
	}
	
	// *** Constructors

	public IRSResourceSet(String id, NodeType nodeType, Position position, int tokens) {
		super(id, nodeType, position, tokens);
		createSample();// TODO remove
	}
	
	public IRSResourceSet(String id, Position position, int tokens) {
		super(id, position, tokens);
		createSample();
	}

	public IRSResourceSet(Position position) {
		super(position);
		createSample();
	}
	
	// *** Methods

	public AtomicSubnet getAtomicWorkflow(AtomicSubnet atomicSubnet) {
		// Ignoring ResourceSet in atomic workflow.
		return atomicSubnet;
	}
	
	private void createSample() {
		// TODO Delete!
		RoleInstance roleInstanceA = new RoleInstance(new Role("A"), 1);
		RoleInstance roleInstanceB = new RoleInstance(new Role("B"), 1);
		RoleInstance roleInstanceC = new RoleInstance(new Role("C"), 1);
		
		Set<RoleInstance> setA = new LinkedHashSet<RoleInstance>();
		Set<RoleInstance> setAB = new LinkedHashSet<RoleInstance>();
		Set<RoleInstance> setABC = new LinkedHashSet<RoleInstance>();
		Set<RoleInstance> setC = new LinkedHashSet<RoleInstance>();
		
		setA.add(roleInstanceA);
		setAB.add(roleInstanceA);
		setAB.add(roleInstanceB);
		setABC.add(roleInstanceA);
		setABC.add(roleInstanceB);
		setABC.add(roleInstanceC);
		setC.add(roleInstanceC);
		
		
		Resource resourceA = new Resource(setA);
		Resource resourceAB = new Resource(setAB);
		Resource resourceABC = new Resource(setABC);
		Resource resourceC = new Resource(setC);
		
		getResources().add(resourceA);
		getResources().add(resourceAB);
		getResources().add(resourceABC);
		getResources().add(resourceC);
		
		addTokens(1);
	}
}
